package com.itcast.demo_one.kotlin

fun main(){
    val car1 = Car("自行车")
    car1.show()
    val car2 = Car("小轿车")
    car2.show()
    val car3 = Car("大货车")
    car3.show()
    val car4 = Car("三轮车")
    car4.show()
}

class Car(var name :String){
    var wheels = 0
    //  初始代码块
    init {
        wheels = when(name){
            "自行车" -> 2
            "小轿车" -> 4
            "大货车" -> 8
            else -> 3
        }
    }
    constructor(name: String, wheels: Int):this(name){
        this.wheels = wheels
    }
    fun show(){
        println("车辆名称：$name, 车轮数量：$wheels")
    }

}